﻿#ifndef FIREWORKBASE_H
#define FIREWORKBASE_H

#include <memory>
#include <random>

#include "FireworkParticle.h"

enum class FireworkState {
	Flying,
	Blast,
	Done
};

class Firework {
public:
	Firework(vsg::dvec3 pos, float speed, uint32_t count) : m_pos{ pos }, z_speed{ speed }, m_fireworkParticlesCount{ count } {
		std::random_device rd;  // 将用于获得随机数引擎的种子
		m_gen = std::mt19937_64(rd()); // 以 rd() 播种的标准 mersenne_twister_engine
	}
	~Firework() {};

	void init();
	void update(const std::chrono::nanoseconds& delt);
	vsg::ref_ptr<vsg::Node> getNode();

	bool isDone() {
		return m_state == FireworkState::Done;
	};

	void reset(vsg::dvec3 pos, double speed = 60);

	void activate();

protected:
	void addNewBombs(vsg::dvec3 pos, const std::vector<vsg::dvec3>& speedList, vsg::vec4 color, uint8_t lengthBomb);

private:
	void invalid();
	void initNode();
	void setBombsMovePara(int begin, int end);
	void initBombRandom(vsg::dvec3 pos);
	void initBombBall(vsg::dvec3 pos);
	void initBombCircle(vsg::dvec3 pos);
	void initBombCircles(vsg::dvec3 pos);
	void initBombCone(vsg::dvec3 pos);
	void initBombLittleLines(vsg::dvec3 pos);
	void initBombLines(vsg::dvec3 pos);
	void initBombLinesAndInBall(vsg::dvec3 pos);
	void initBombCircleAndInBall(vsg::dvec3 pos);
	void initBombRosebush(vsg::dvec3 pos);

protected:
	std::vector<FireworkParticle> m_fireworkParticles;
	vsg::dvec3 m_pos;
	std::mt19937_64 m_gen;

private:
	FireworkState m_state{ FireworkState::Flying };
	double z_speed;
	vsg::ref_ptr<vsg::MatrixTransform> m_matrixTransform;
	vsg::ref_ptr<vsg::Switch> m_switch;
	uint32_t m_fireworkParticlesCount;
	uint32_t m_activateFireworkParticlesCount{ 0 };
};

#endif
